package com.example.xianzhi.controller.API;

import cn.hutool.json.JSONUtil;
import com.example.xianzhi.dao.AdSmallDao;
import com.example.xianzhi.dao.impl.AdSmallDaoImpl;
import com.example.xianzhi.entity.TbAdSmall;
import org.lanqiao.mvc.entity.YockMvcAnnotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@YockMvcAnnotation.Controller("/api_AdSmall")
public class Api_AdSmallController {
    private AdSmallDao adSmallDao = new AdSmallDaoImpl();
    @YockMvcAnnotation.RequestMapping("/getAllType.do")
    @YockMvcAnnotation.ResponseBody
    public String getAllType(
            HttpServletRequest request,
            HttpServletResponse response,
            @YockMvcAnnotation.RequestParam(name = "goods_id") int  goods_id
    ) {
        //允许的请求的域是*，代表所有
        response.setHeader("Access-Control-Allow-Origin","*");
        Map<String, Object> map = new HashMap<>();
        response.setContentType("application/json;charset=utf-8");  //告诉前端返回来的是一个json对象
        List<TbAdSmall> tbAdSmall = adSmallDao.selectSmall(goods_id);
        map.put("code",200);
        map.put("data",tbAdSmall);
        String jsonStr = JSONUtil.toJsonStr(map);
        return jsonStr;
    }
}
